<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<style>
    td > ul {
        margin-left: 0;
        padding-left: 16px;
    }
    .btn.addRole, .btn.plus{
        margin-left:2px;
    }
</style>

<!-- row -->
<div class="row">
    <article class="col-sm-12 col-md-12 col-lg-12 sortable-grid ui-sortable">
        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget well" id="wid-id-3" data-widget-colorbutton="false" data-widget-editbutton="false"
             data-widget-togglebutton="false" data-widget-deletebutton="false" data-widget-fullscreenbutton="false"
             data-widget-custombutton="false" data-widget-sortable="false">
            <header>
                <!--<span class="widget-icon"> <i class="fa fa-comments"></i> </span>-->
                <!--<h2>Default Tabs with border </h2>-->

            </header>

            <!-- widget div-->
            <div>
                <!-- widget edit box -->
                <div class="jarviswidget-editbox">
                    <!-- This area used as dropdown edit box -->

                </div>
                <!-- end widget edit box -->

                <!-- widget content -->
                <div class="widget-body">
                    <h4><spring:message code="PERMISSION_SETTINGS"/></h4>
                    <hr class="simple">

                    <div class="row">

                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 ">

                            <table class="table table-forum table-hover analysis" width="100%">
                                <thead>
                                <tr>
                                    <th><spring:message code="PERMISSION_FOR_ANALYSIS"/></th>
                                    <th class="col-sm-3"><spring:message code="PERMISSION_ROLE"/></th>
                                    <th style="width: 80px;"><spring:message code="PERMISSION_OPERATION"/></th>
                                </tr>
                                </thead>
                                <tbody>
                                <!-- TR -->
                                <c:forEach items="${resourceDtos['ANALYSIS']}" var="permission">
                                    <c:choose>
                                        <c:when test="${fn:startsWith(permission.code, 'analysis:*')}">
                                            <tr class="bg bg-danger">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span> ${permission.name} </span>
                                                        </h4>
                                                        <small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);" class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:when test="${fn:contains(permission.code,':*') }" >
                                            <tr class="bg bg-warning">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:otherwise>
                                            <tr class="bg">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:otherwise>
                                    </c:choose>

                                </c:forEach>
                                <!-- end TR -->

                                </tbody>
                            </table>

                            <table class="table table-forum table-hover project" width="100%">
                                <thead>
                                <tr>
                                    <th><spring:message code="PERMISSION_FOR_PROJECT"/></th>
                                    <th class="col-sm-3"><spring:message code="PERMISSION_ROLE"/></th>
                                    <th style="width: 80px;"><spring:message code="PERMISSION_OPERATION"/></th>
                                </tr>
                                </thead>
                                <tbody>
                                <!-- TR -->
                                <c:forEach items="${resourceDtos['PROJECT']}" var="permission">
                                    <c:choose>
                                        <c:when test="${fn:startsWith(permission.code, 'project:*')}">
                                            <tr class="bg bg-danger">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span> ${permission.name} </span>
                                                        </h4>
                                                        <small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:when test="${fn:contains(permission.code,':*') }" >
                                            <tr class="bg bg-warning">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:otherwise>
                                            <tr class="bg">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:otherwise>
                                    </c:choose>

                                </c:forEach>
                                <!-- end TR -->

                                </tbody>
                            </table>

                            <table class="table table-forum table-hover data" width="100%">
                                <thead>
                                <tr>
                                    <th><spring:message code="PERMISSION_FOR_DATA"/></th>
                                    <th class="col-sm-3"><spring:message code="PERMISSION_ROLE"/></th>
                                    <th style="width: 80px;"><spring:message code="PERMISSION_OPERATION"/></th>
                                </tr>
                                </thead>
                                <tbody>
                                <!-- TR -->
                                <c:forEach items="${resourceDtos['DATAIMPORT']}" var="permission">
                                    <c:choose>
                                        <c:when test="${fn:startsWith(permission.code, 'data:*')}">
                                            <tr class="bg bg-danger">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span> ${permission.name} </span>
                                                        </h4>
                                                        <small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:when test="${fn:contains(permission.code,':*') }" >
                                            <tr class="bg bg-warning">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:otherwise>
                                            <tr class="bg">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:otherwise>
                                    </c:choose>

                                </c:forEach>
                                <!-- end TR -->

                                </tbody>
                            </table>

                            <table class="table table-forum table-hover system" width="100%">
                                <thead>
                                <tr>
                                    <th><spring:message code="PERMISSION_FOR_SYSTEM"/></th>
                                    <th class="col-sm-3"><spring:message code="PERMISSION_ROLE"/></th>
                                    <th style="width: 80px;"><spring:message code="PERMISSION_OPERATION"/></th>
                                </tr>
                                </thead>
                                <tbody>
                                <!-- TR -->
                                <c:forEach items="${resourceDtos['SYSTEM']}" var="permission">
                                    <c:choose>
                                        <c:when test="${fn:startsWith(permission.code, 'system:*')}">
                                            <tr class="bg bg-danger">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span> ${permission.name} </span>
                                                        </h4>
                                                        <small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:when test="${fn:contains(permission.code,':*') }" >
                                            <tr class="bg bg-warning">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:when>
                                        <c:otherwise>
                                            <tr class="bg">
                                                <td>
                                                    <h4>
                                                        <h4>
                                                            <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span> ${permission.name} </span>
                                                        </h4>
                                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><small>${permission.description}</small>
                                                    </h4>
                                                </td>
                                                <td>
                                                    <ul permissionId= ${permission.id} permissionCode= ${permission.code}>
                                                        <c:forEach items="${permission.roles}" var="role">
                                                            <li class="haveRole">${role.name} (<a href="javascript:void(0);"
                                                                                                  class="deleteRole"
                                                                                                  roleId= ${role.id} permissionCode= ${permission.code}><spring:message
                                                                    code="PERMISSION_DELETE"/></a>)
                                                            </li>
                                                        </c:forEach>
                                                    </ul>
                                                </td>
                                                <td class="havRole">
                                                    <a href="javascript:void(0);" class="btnRole"
                                                       permissionId= ${permission.id} permissionCode= ${permission.code}><spring:message
                                                            code="PERMISSION_ROLE"/></a>
                                                </td>
                                            </tr>
                                        </c:otherwise>
                                    </c:choose>

                                </c:forEach>
                                <!-- end TR -->

                                </tbody>
                            </table>

                        </div>
                    </div>
                    <!-- end widget content -->
                </div>
                <!-- end widget div -->
            </div>

        </div>
        <!-- end widget -->
    </article>
</div>
<!-- end row -->
<table style="display: none;" id="tb_edit">
<tbody>
<tr class="edit">
</tr>
</tbody>
</table>
<script src="js/core/business/permission/permissionInit.js"></script>
